package com.supcalls.thread_pool.callable;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class MyThread implements Callable<String> {
    private int count = 20;

    @Override
    public String call() throws Exception {
        count = count -1;
        System.out.println(Thread.currentThread().getName()+"当前票数：" + count);
        return "sale out";
    }

    public static void main(String[] args) throws InterruptedException, ExecutionException {
        Callable<String> callable  =new MyThread();
        FutureTask <String>futureTask=new FutureTask<>(callable);
        FutureTask <String>futureTask1=new FutureTask<>(callable);
        FutureTask <String>futureTask2 =new FutureTask<>(callable);

        Thread mThread=new Thread(futureTask,"thread1");
        Thread mThread2=new Thread(futureTask1,"thread2");
        Thread mThread3=new Thread(futureTask2,"thread3");

        mThread.start();
        mThread2.start();
        mThread3.start();

        System.out.println(futureTask.get());
        System.out.println(futureTask1.get());
        System.out.println(futureTask2.get());

    }
}